package com.example.demo.config;

import io.netty.util.concurrent.DefaultThreadFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.*;

@Configuration
public class ThreadPoolConfig {

    @Bean("common")
    public Executor getThread() {
        DefaultThreadFactory threadFactory = new DefaultThreadFactory("common");
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(8, 8, 60,
                TimeUnit.SECONDS, new LinkedBlockingQueue<>(100), threadFactory, new ThreadPoolExecutor.CallerRunsPolicy());
        return threadPoolExecutor;
    }

    @Bean("sendEmail")
    public Executor emailThread() {
        DefaultThreadFactory threadFactory = new DefaultThreadFactory("sendEmail");
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(8, 8, 60,
                TimeUnit.SECONDS, new LinkedBlockingQueue<>(100), threadFactory, new ThreadPoolExecutor.CallerRunsPolicy());
        return threadPoolExecutor;
    }
}
